﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:system="clr-namespace:System;assembly=mscorlib"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:vsm ="clr-namespace:System.Windows;assembly=PresentationFramework"
                    xmlns:SF_Converters="clr-namespace:ScrumFactory.Windows.Helpers.Converters;assembly=ScrumFactory.Windows.Helpers">

    
    <SF_Converters:SprintCalendarDayConverter x:Key="SprintCalendarDayConverter"/>
    <SF_Converters:HolidayConverter x:Key="HolidayConverter"/>
    

    <ControlTemplate x:Key="DatePickerTextBox">
        <TextBox Text="{Binding Path=SelectedDate, StringFormat='{}{0:d}', RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" Width="100" />
    </ControlTemplate>

    <Style TargetType="{x:Type DatePickerTextBox}">        
        <Setter Property="Control.Template" Value="{StaticResource DatePickerTextBox}"/>        
    </Style>

   

    <Style x:Key="CalendarDayButtonStyle" TargetType="{x:Type CalendarDayButton}">
        <Setter Property="ToolTip" Value="{Binding ., Converter={StaticResource HolidayConverter}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type CalendarDayButton}">
                    
                    <Grid Margin="0,0,0,0">



                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualTransition GeneratedDuration="0:0:0.1" />
                                </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Background" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" />
                                    </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Background" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" />
                                    </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Background" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />                                        
                                    </Storyboard>
                                    </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="SelectionStates">
                                <vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualTransition GeneratedDuration="0" />
                                </vsm:VisualStateGroup.Transitions>
                                <vsm:VisualState x:Name="Unselected" />
                                <vsm:VisualState x:Name="Selected">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="SelectedBackground" Storyboard.TargetProperty="Opacity" To=".75" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="selectedText" Storyboard.TargetProperty="Color" To="White" Duration="0"/>
                                    </Storyboard>

                                </vsm:VisualState>
                            </vsm:VisualStateGroup>

                            <vsm:VisualStateGroup x:Name="ActiveStates">
                                <vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualTransition GeneratedDuration="0" />
                                </vsm:VisualStateGroup.Transitions>
                                <vsm:VisualState x:Name="Active" />
                                <vsm:VisualState x:Name="Inactive">
                                    <Storyboard>
                                        <ColorAnimation Duration="0" Storyboard.TargetName="selectedText" Storyboard.TargetProperty="Color" To="#FF777777"></ColorAnimation>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="DayStates">
                                <vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualTransition GeneratedDuration="0" />
                                </vsm:VisualStateGroup.Transitions>
                                <vsm:VisualState x:Name="RegularDay" />
                                <vsm:VisualState x:Name="Today">
                                    <Storyboard>
                                        <!--<DoubleAnimation Storyboard.TargetName="TodayBackground" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />-->
                                        <ColorAnimation Duration="0" Storyboard.TargetName="selectedText" Storyboard.TargetProperty="Color" To="Red"></ColorAnimation>
                                    </Storyboard>
                                    </vsm:VisualState>
                            </vsm:VisualStateGroup>
                                <vsm:VisualStateGroup x:Name="BlackoutDayStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0" />
                                        </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="NormalDay" />
                                    <vsm:VisualState x:Name="BlackoutDay">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" Storyboard.TargetName="Blackout" Storyboard.TargetProperty="Opacity" To=".2"/>
                                    </Storyboard>
                                        </vsm:VisualState>
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>

                        <Rectangle x:Name="weekend" 
                                   Fill="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Visibility="Collapsed" />
                        
                        <Border
                                x:Name="InSprintDayBackground" IsHitTestVisible="False"
                                BorderThickness="0,1,0,1" BorderBrush="Orange"
                                Background="Yellow" Opacity="0.5"/>

                        <Rectangle x:Name="TodayBackground" RadiusX="5" RadiusY="5" Opacity="0" Fill="Orange"/>

                        <Rectangle x:Name="SelectedBackground" RadiusX="5" RadiusY="5" Opacity="0" Fill="Red"/>
                        <Rectangle x:Name="Background" RadiusX="1" RadiusY="1" Opacity="0" Fill="{TemplateBinding Background}"/>
                        <ContentPresenter
                                    x:Name="NormalText" 
                                    TextElement.FontSize="{StaticResource NormalFontSize}"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"                                
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"                                    
                                    Margin="6,2,6,2">
                            <TextElement.Foreground>
                                <SolidColorBrush x:Name="selectedText" Color="Black"/>
                            </TextElement.Foreground>

                        </ContentPresenter>

                        <Rectangle x:Name="holiday" 
                                   Fill="Green" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.5" />

                        



                        <Path x:Name="Blackout" Opacity="0" Margin="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" Fill="#FF000000" Stretch="Fill" Data="M8.1772461,11.029181 L10.433105,11.029181 L11.700684,12.801641 L12.973633,11.029181 L15.191895,11.029181 L12.844727,13.999395 L15.21875,17.060919 L12.962891,17.060919 L11.673828,15.256231 L10.352539,17.060919 L8.1396484,17.060919 L10.519043,14.042364 z"/>
                        <Rectangle x:Name="DayButtonFocusVisual" Visibility="Collapsed" RadiusX="5" RadiusY="5" Fill="Yellow" Opacity="0.5" Cursor="Hand"/>
                        
                                   
                                   
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="DayButtonFocusVisual" Property="Visibility" Value="Visible" />
                        </Trigger>
                        
                        <Trigger Property="ToolTip" Value="{x:Null}">
                            <Setter TargetName="holiday" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        
                        <DataTrigger Binding="{Binding DayOfWeek}" Value="Sunday">
                            <Setter TargetName="weekend" Property="Visibility" Value="Visible" />
                        </DataTrigger>

                        <DataTrigger Binding="{Binding DayOfWeek}" Value="Saturday">
                            <Setter TargetName="weekend" Property="Visibility" Value="Visible" />
                        </DataTrigger>


                        <!-- This DataTrigger is new -->
                        <DataTrigger Value="0">
                            <DataTrigger.Binding>
                                <MultiBinding Converter="{StaticResource SprintCalendarDayConverter}">
                                    <Binding RelativeSource="{RelativeSource AncestorType=Calendar}" Path="DataContext.Sprint"/>
                                    <Binding Path="." />
                                </MultiBinding>
                            </DataTrigger.Binding>
                            <Setter TargetName="InSprintDayBackground" Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                        <DataTrigger Value="1">
                            <DataTrigger.Binding>
                                <MultiBinding Converter="{StaticResource SprintCalendarDayConverter}">
                                    <Binding RelativeSource="{RelativeSource AncestorType=Calendar}" Path="DataContext.Sprint"/>
                                    <Binding Path="." />
                                </MultiBinding>
                            </DataTrigger.Binding>
                            <Setter TargetName="NormalText" Property="TextElement.FontWeight" Value="Bold"/>
                            <Setter TargetName="InSprintDayBackground" Property="CornerRadius" Value="5,0,0,5" />
                            <Setter TargetName="InSprintDayBackground" Property="BorderThickness" Value="1,1,0,1" />
                        </DataTrigger>
                       
                        <DataTrigger Value="3">
                            <DataTrigger.Binding>
                                <MultiBinding Converter="{StaticResource SprintCalendarDayConverter}">
                                    <Binding RelativeSource="{RelativeSource AncestorType=Calendar}" Path="DataContext.Sprint"/>
                                    <Binding Path="." />
                                </MultiBinding>
                            </DataTrigger.Binding>
                            <Setter TargetName="NormalText" Property="TextElement.FontWeight" Value="Bold"/>
                            <Setter TargetName="InSprintDayBackground" Property="CornerRadius" Value="0,5,5,0" />
                            <Setter TargetName="InSprintDayBackground" Property="BorderThickness" Value="0,1,1,1" />
                        </DataTrigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Calendar}">
        <Setter Property="FirstDayOfWeek" Value="Monday"/>
        <Setter Property="CalendarDayButtonStyle" Value="{StaticResource CalendarDayButtonStyle}"/>
    </Style>

    <Style TargetType="{x:Type DatePicker}">
        <Setter Property="CalendarStyle" Value="{StaticResource {x:Type Calendar}}"/>
        <Setter Property="FirstDayOfWeek" Value="Monday"/>
        <Setter Property="BorderThickness" Value="0"/>
        
    </Style>

</ResourceDictionary>